<?php
/**
 * Created by PhpStorm.
 * User: shichen
 * Date: 2018/11/1
 * Time: 20:34
 */

namespace app\admin\controller;

use app\admin\model\Comment as commentModel;
use think\Controller;
use think\Db;
use think\Request;
class Comment extends Admin
{
    public function _initialize()
    {
        parent::_initialize();
        $this->comment = new commentModel();
    }

    public function index()
    {

        $Auser=new commentModel();
        $list=Db::table('comment')->select();
//        var_dump($list);die;
        return view('admin@comment/index', [
            'list' => $list
        ]);

    }

    public function edit($id)
    {
//        var_dump($id);die;
        $list = $this->comment->find($id);
//        var_dump($list);die;
        return view('admin@comment/fun3', [
            'list' => $list
        ]);
    }

    public function update(Request $request, $id)
    {
        $p = $request->post();
//        var_dump($p);die;
        $data['cid']=$p['cid'];
        $data['gid']=$p['gid'];
        $data['rcontent']=$p['rcontent'];
        $data['time']=time();

//                var_dump($data);die;

        $res=Db::table('reply')->insert($data);
//        var_dump($res);die;
        if ($res > 0) {
            return $this->success('回复成功!', url('admin/Comment/index'));
        } else {
            return $this->error('回复失败!');
        }
    }

//回复那些没有回复过的评论
    public function create()
    {
        $result = Db::table('reply')->alias('r')
            ->join('comment c','c.cid=r.cid')
//            ->whereNotExists('r.cid=c.cid')
            ->select();
        var_dump($result);die;
        return view('admin@con2/func2');
    }


}